<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
    <body>
       <s:include value="../../head.jsp"></s:include>
    <div id="mainContent">
    <script type="text/javascript">
    getPaper();
    function getPaper(){
			var paperId  = $('#paperId').val();
			if(paperId==''){
					alert("请选择评估类型");
				}
			var data1 = 'code=005001001&paramMap.caseHistoryID='+'1'+'&paramMap.pid=1';
			//alert(data1);
			getPaperDesc(data1);
    	}  
	function getPaperDesc(data){
		$.ajax({
    		//ajax请求url
			url:		'ajaxAction',
			//ajax提交方式
			type:	    'post',
			//ajax请求超时时长
			timeout:	'60000',
			//ajax请求参数
			data:	data,
			//请求数据类型，包括json和xml两种
			dataType:	'json',
			//ajax执行前调用函数
			beforeSend:function(request){
				var $img = $("<img>")
					.attr("src","images/wait/loader.gif")
					.attr("width","50")
					.attr("height","50") 
					.attr("border","0");
				$('#myPaper').attr("align","center")
				$('#myPaper').html($img);
			},
			//ajax请求完成后调用函数
			complete:function(request,textStatus){},
			//ajax请求成功调用函数
			success:function(jsonData,textStatus){
				//如果正常返回,设置GRID.data.columnData
				//为ajax请求放回的json格式的数据
				if (textStatus == "success"){
					  	var paper='' ;
						var part=[] ;
						var questions=[] ;
						var answers=[] ;
						var part_head=[];
						var asserts = jsonData.data;
						$.each(asserts,function(i,item){
							var assert =  item ;
							if(assert.atype==='paper'){
									paper = assert;
								}
							else if(assert.atype=='part'){
								part[assert.seq]=assert;
								}
							else if(assert.atype=='ques'){
								if(questions[assert.rid]==undefined){
										questions[assert.rid] = [];
									}
								questions[assert.rid][assert.seq] =assert;
									
								}
							else if(assert.atype=='answer'){
								if(answers[assert.rid]==undefined){
									answers[assert.rid] = [];
								}
								answers[assert.rid][assert.seq] =assert;
								}
							else if(assert.atype=='part_head'){
								if(part_head[assert.rid]==undefined){
									part_head[assert.rid] = [];
								}
								part_head[assert.rid][assert.seq] =assert;
								}
							});
					
					var inht = '<form name="actionForm" method="post" action="operateAction.action?code=005001002" id="actionForm"><table border="0px;" CELLPADDING="10px;" CELLSPACING="10px;"  width="100%" > ';
					 inht +='<tr rowspan="2"><td colspan="2" ailgn="center"><p STYLE="font-size:18pt;" align="center"><strong>'+paper.varName+'</strong></p></td></tr>';
					inht +='<tr ><td colspan="2" ailgn="center" ><p STYLE="font-size:11pt;" align="left"> &nbsp;&nbsp;&nbsp;&nbsp;'+paper.adesc+' </p></td></tr>'
					for(i=1;i<part.length;i++){
						inht +='<tr><td colspan="2"><p STYLE="font-size:10pt;" align="left">'+part[i].varName+'</p></td></tr>';
						if(part[i].adesc!=undefined&&part[i].adesc!=''){
							inht +='<tr><td colspan="2"><p STYLE="font-size:8pt;" align="left">'+part[i].adesc+'</p></td></tr>';	
							}
						if(part_head[part[i].assertId]!=undefined&&part_head[part[i].assertId]!=''){
							var temheads =part_head[part[i].assertId];
							inht += '<tr><td colspan = "2"> <table  CELLPADDING="1px;" CELLSPACING="0px;" border="1px;" width="100%"><tr><td width="10%">&nbsp;</td><td align="center" width="30%">&nbsp;</td>';
								var temlength =temheads.length;
								var widn = 60/temheads.length ;
								var wid = Number(widn) +"%";
								
							//inht +='<tr><td width="50%"></td><td width="50%"><table CELLPADDING="1px;" CELLSPACING="0px;" border="0px;" width="100%"><tr>' ;
							for(j=1;j< temheads.length;j++){
								inht+=	'<td align="center" width="'+wid+'">';
								inht+= temheads[j].varName;
								inht += '</td>';
								}
							inht+='</tr>';
							if(questions[part[i].assertId]!=undefined&&questions[part[i].assertId]!=''){
									var temques = questions[part[i].assertId] ;
									for(j=1;j<temques.length;j++){
											var temqu = temques[j];
											inht +='<tr><td width="10%"><p align="center">'+temqu.seq+'</p>'
											inht +='<td width ="30%" align="center"><p align="center" style="font-size:10pt;">'+temqu.varName+'</td>';
											for(m=1;m<temheads.length;m++){
													inht +='<td width="'+wid+'" align="center"><input type ="radio" value="'+temheads[m].assertId+'"  name="paramMap.name_'+temqu.assertId+'"  id="id_'+temqu.assertId+'" /> </td>'
												}
											
										}
									inht +='</tr>'
								}
							inht +='</table></td></tr>'
							
							} else {
								var temques =[];
								if(questions[part[i].assertId]!=undefined&&questions[part[i].assertId]!=''){
										temques = questions[part[i].assertId];
									}
								for(j=1;j<temques.length;j++){
									var temqu = temques[j];
									inht +='<tr><td width="10%"><p align="right" style="font-size:10pt;">'+temques[j].seq +'.</p></td><td width="90%" align="left"><p align="left" style="font-size:10pt;">'+temques[j].varName+'</p></td></tr>';

										if( temques[j].subType!=undefined&& temques[j].subType=='si_ch'){
											if(answers[temques[j].assertId]!=undefined&&answers[temques[j].assertId]!=''){
													temans =  answers[temques[j].assertId];
													for(p=1;p<temans.length;p++){
														inht+='<tr><td width="10%" align="center"></td>'
														inht+='<td width="90%" align="left"><p align="left" style="font-size:10pt;"><input type="radio" name="paramMap.name_'+temqu.assertId+'"  value="'+temans[p].assertId+'" id="id_'+temqu.assertId+'" />' + temans[p].varName + '</p> </ td> </ tr>'	
													}
												}
											}
										if( temques[j].subType!=undefined&& temques[j].subType=='si_ch_bl'){
											if(answers[temques[j].assertId]!=undefined&&answers[temques[j].assertId]!=''){
													temans =  answers[temques[j].assertId];
													for(p=1;p<temans.length;p++){
														inht+='<tr><td width="10%" align="center"></td>'
														inht+='<td width="90%" align="left"><p align="left" style="font-size:10pt;"><input type="radio" name="paramMap.name_'+temqu.assertId+'"  value="'+temans[p].assertId+'" id="id_'+temqu.assertId+'" />';
														var sstr = temans[p].varName;
														var spd = '|||||';
														var indd = 1;
														while(sstr.indexOf(spd)>=0){
															var sde = '&nbsp;&nbsp;<input type="text" name="paramMap.name_'+temans[p].assertId+'_'+indd+' " id="id_'+temans[p].assertId+'_'+indd+'" length="5">&nbsp;&nbsp;';
															sstr = replaceFirst(sstr,spd,sde);
															indd++;
														}
														inht +=sstr+ '</p>';
														
														inht += ' </ td> </ tr>';	
													}
												}
											}
										if( temques[j].subType!=undefined&& temques[j].subType=='mu_ch'){
											if(answers[temques[j].assertId]!=undefined&&answers[temques[j].assertId]!=''){
													temans =  answers[temques[j].assertId];
													for(p=1;p<temans.length;p++){
														inht+='<tr><td width="10%" align="center"></td>'
														inht+='<td width="90%" align="left"><p align="left" style="font-size:10pt;"><input type="checkbox" name="paramMap.name_'+temqu.assertId+'"  value="'+temans[p].assertId+'" id="id_'+temqu.assertId+'" />' + temans[p].varName + '</p> </ td> </ tr>'	
													}
												}
											}
										if( temques[j].subType!=undefined&& temques[j].subType=='bl'){
											if(answers[temques[j].assertId]!=undefined&&answers[temques[j].assertId]!=''){
													temans =  answers[temques[j].assertId];
													for(p=1;p<temans.length;p++){
														inht+='<tr><td colspan="2" align="center">'
														 
														inht+= '<input type="text" name="paramMap.name_'+temans[p].assertId+'_'+indd+' " id="id_'+temans[p].assertId+'_'+indd+'" length="5">&nbsp;&nbsp;';
														inht += ' </ td> </ tr>';	
													}
												}
											}

										
										
									}

								}
					
						}
				 		inht +='<tr><td colspan="2" align="center">';
				 		inht +='<input type="submit" value="提交"/>';
				 		inht +='</td></tr>';
						inht +='</table></form>';
						$('#myPaper').html(inht);
					
				}
			}
        	});

		}

	function replaceFirst(str,regex,replacement){
			var index = str.indexOf(regex);
			var imf = str.substring(0,index);
			var lef = str.substring(index+regex.length);
			 
			return imf+replacement +lef;
		 }


	function checkAll(){
			
		}
    </script>
    	<div id="baseInfo">
    		<div class="MGTop" id="condition">
     	 	<div class="module" id="myPaper">
     	 	<h2>病情评估
     	 	</h2>
     	 	<br />
     	 	<br />
     	 	<br />
     	 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: ''cb'ce'cc'e5'; color: rgb(0, 0, 0); font-size: 15px;">请选择病情评估表类型:</span>
     	 	&nbsp;&nbsp;&nbsp;&nbsp;<select id ="paperId" name="paperName">
     	 		<s:iterator value="initMap.papers" id="index">
     	 			<option value='<s:property value="assertId"/>'><s:property value="varName"></s:property></option>
     	 		</s:iterator>
     	 	</select>
     	 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="queding_ss" onclick='javaScript:getPaper();' type="button" value="确定" /> 
     	 	 	<br />
     	 	 		<br />
     	 	 			<br />
     	 	<br />
     	 	&nbsp;&nbsp;&nbsp;&nbsp;<b>录入须知：</b>
     	 		<br />
     	 	&nbsp;&nbsp;&nbsp;&nbsp;<span>1. 录入后信息不允许修改，只能新增</span>
     	 	<br />
     	 	&nbsp;&nbsp;&nbsp;&nbsp;<span>2. 录入时需要填写进行检查或评估的时间</span>
     	 	<br />
     	 	 			<br />
     	 	 			<br />
     	 	 			<br />
     	 	</div>
     	 	</div>
    	 </div>
    </div>
    </body>
